\documentclass{article}

\usepackage{amsmath}
\usepackage{graphicx}

\usepackage{fancyhdr}
\fancyhf{}
\lhead{Andrew O'Neill}
\rhead{Homework 1}

\begin{document}

\section{A}
\subsection{a}
% code for A.a
\begin{verbatim}
> w=rnorm(150, 0,1)
> x=filter(w, filter=c(0,-.9), method="recursive")[-(1:50)]
> png("D:/Users/Andrew/Desktop/plot1.png")
> plot.ts(x)
> ma=filter(x, sides=1, rep(1,4)/4)
> lines(ma, col="red", lty="dashed")
> dev.off()
\end{verbatim}
\includegraphics[width=2.5in, height=2.5in]{plot1.png}

\subsection{b}
% code for A.b
\begin{verbatim}
> png("D:/Users/Andrew/Desktop/plot2.png")
> c = cos((2*pi*(1:100))/4)
> plot.ts(c, main=expression(x[t]==2*cos(2*pi*t/4)))
> ma=filter(c,sides=1,rep(1,4)/4)
> lines(ma, col="red", lty="dashed")
> dev.off()
\end{verbatim}
\includegraphics[width=2.5in, height=2.5in]{plot2.png}

\subsection{c}
% code for A.c
\begin{verbatim}
> png("D:/Users/Andrew/Desktop/plot3.png")
> c = cos((2*pi*(1:100))/4)
> w = rnorm(100, 0, 1)
> plot.ts(c+w, main=expression(x[t]==2*cos(2*pi*t/4) + N(0,1)))
> ma=filter(c+w, sides=1, rep(1,4)/4)
> lines(ma, col="red", lty="dashed")
> dev.off()
\end{verbatim}
\includegraphics[width=2.5in, height=2.5in]{plot3.png}

\section{B}
\subsection{a}
% code for B.a
\begin{verbatim}
> s =c (rep(0,100), 10*exp(-(1:100)/20)*cos(2*pi*1:100/4))
> x = ts(s + rnorm(200,0,1))
> png("/home/oneill/plot3.png")
> plot(x)
> lines(rep(mean(x),200), col="red", lty="dashed")
> dev.off()
\end{verbatim}
\includegraphics[width=2.5in, height=2.5in]{plot4.png}

\subsection{b}
% code for B.b
\begin{verbatim}
> x.acf <- acf(x, 200, type="covariance")
> png("/home/oneill/plot4.png")
> plot(x.acf)
> dev.off()
\end{verbatim}
\includegraphics[width=2.5in, height=2.5in]{plot5.png}

\section{C}
% code for C
\begin{displaymath}
	\begin{aligned}
		x_t &= \delta + x_{t-1} + \omega_t \\
		&= \delta t + \sum_{j=1}^{t} w_j
	\end{aligned}
\end{displaymath}
Because $E(\omega_t) = 0$ for all t, and $\delta$ is a constant, we have
\begin{displaymath}
	\mu_{xt} = E(x_t) = \delta t + \sum_{j=1}^{t}E(\omega_j)=\delta t \qquad \text{mean}
\end{displaymath}
\begin{displaymath}
	\gamma_x(s, t) = covt(x_s, x_t) = cov\left(\sum_{j=1}^s \omega_j, \sum_{k=1}^t \omega_k \right) = min \{s, t\} \sigma_\omega^2 \qquad \text{ACF}
\end{displaymath}

\end{document}
